import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import usm_make
import usm_entropy
def ngon_coords(verts):
radians=[]
for k in range(verts):
rad = (2*np.pi*k)/verts
radians.append(rad)
x_vals = np.cos(radians)
y_vals =np.sin(radians)
return x_vals, y_vals
%matplotlib notebook
verts = 3
points = 3000
#x_vals, y_vals = ngon_coords(verts)
x_vals = np.array([-1, 0, 1])
y_vals = np.array([0, 1, 0])
vert_coords = np.column_stack((x_vals, y_vals))
xmin = x_vals.min() - 0.2
xmax = x_vals.max() + 0.2
ymin = y_vals.min() - 0.2
ymax = y_vals.max() + 0.2
#c is starting coordinate
c = np.array([0.5, 0.5])
#initiate figure instance
fig, ax = plt.subplots(figsize=(4, 4))
ax.set(xlim=(xmin, xmax), ylim=(ymin, ymax))
scat, = ax.plot([],[])
"""
ax.set(xlim=(xmin, xmax), ylim=(ymin, ymax))
ax.scatter(x=0.5, y=0.5, s=2, c='r', label='inital point')
ax.scatter(x_vals, y_vals, c='b', label='vertices')
"""
def init_frame():
global ax
ax.cla()
ax.set(xlim=(xmin, xmax), ylim=(ymin, ymax))
ax.scatter(x=0, y=0.25, s=2, c='r', label='inital point')
ax.scatter(x_vals, y_vals, c='b', label='vertices')
ax.legend()
#for i, xy in enumerate(zip(x_vals, y_vals)):
#ax.annotate(f'{i}', xy, xycoords='data', xytext=xy, textcoords='offset points')
rng = np.random.default_rng()
coords = [c]
randints = rng.integers(0, verts, points)
chunks = 1
frame_chunks = points // chunks
firstpts = 10
for i in randints:
coords.append((coords[-1] + vert_coords[i])/2)
def firstpoints(i):
i_from = i * chunks
i_to = i_from + chunks
rows = coords[i_from:i_to]
x, y = zip(*rows)
ax.scatter(x, y, s=2, c='g')
def animation(i):
i_from = i * chunks
# are we on the last frame?
if i_from + chunks > len(coords) - 1:
i_to = len(coords) - 1
else:
i_to = i_from + chunks
rows = coords[i_from:i_to]
x, y = zip(*rows)
ax.scatter(x, y, s=2, c='g')
anislow = FuncAnimation(fig, animation, frames=firstpts, init_func=init_frame, interval=1000, repeat=True, blit=True)
#anifast = FuncAnimation(fig, animation, frames=frame_chunks, init_func=init_frame, interval=0.5, repeat=True, blit=True)
movie1 = anislow.to_jshtml()
from IPython.display import HTML
HTML(movie1)
%matplotlib notebook
fig, ax = plt.subplots(figsize=(4, 4))
ax.set(xlim=(xmin, xmax), ylim=(ymin, ymax))
chunks = 20
frame_chunks = points // chunks
anifast = FuncAnimation(fig, animation, frames=frame_chunks, init_func=init_frame, interval=0.5, repeat=True, blit=True)
movie2 = anifast.to_jshtml()
HTML(movie2)
movie1 = ani.to_jshtml()
with open('sierpinski_fast.html', 'w') as fhand:
fhand.write(movie2)
#ani.save('sierpinski_cgr.gif', )
with open('sierpinski.html', 'r') as fhand:
html = fhand.read()
from IPython.display import HTML
HTML(html)
'''raw:: :file: sierpinski.html '''
ss = np.random.SeedSequence()
entropy = ss.entropy
print(entropy)
60019491049027694951583445825735387161
t = np.array([[1, 2], [3, 4]])
t[0]
array([1, 2])